/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package students;

import students.entity.Message;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import students.utils.HibernateUtil;
 
public class Main {
 
    // Данный метод просто показывает, как делается запрос при работе на уровне JDBC
    private void oldJDBC() {
        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        try { 
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_greetgo", "root", "barcelona");
            statement = connection.createStatement();
            List<Message> list = new ArrayList<Message>();
            //rs = statement.executeQuery("insert into hello values('Nurda hi')");
            rs = statement.executeQuery("select message_text from hello");
            while (rs.next()) {
                Message r = new Message();
                r.setMessageText(rs.getString("message_text"));
               // list.add(r);
                System.out.println(r.getMessageText());
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
            System.err.println("Error SQL execution: " + ex.getMessage());
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            System.err.println("Error SQL execution: " + ex.getMessage());
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (statement != null) {
                    statement.close();
                }
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
                System.err.println("Error: " + ex.getMessage());
            }
        }
    }
}